﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EzyGoEzySystem.Models;

namespace EzyGoEzySystem.Controllers
{ 
    public class SummaryController : Controller
    {
        private EzyGoEzyDBContext db = new EzyGoEzyDBContext();

        //
        // GET: /Summary/

        public ViewResult Index()
        {
            var journalEntries = new List<object>();
            var paymentJournalEntries = db.PaymentJournalEntries.Include(p => p.Account);
            var travelJournalEntries = db.TravelJournalEntries.Include(p => p.Account);
            journalEntries.AddRange(paymentJournalEntries);
            journalEntries.AddRange(travelJournalEntries);
            return View(journalEntries.ToList());
            //return View();
        }

        //
        // GET: /Summary/Details/5

        public ViewResult Details(int id)
        {
            PaymentJournalEntry paymentjournalentry = db.PaymentJournalEntries.Find(id);
            return View(paymentjournalentry);
        }

        //
        // GET: /Summary/Create

        public ActionResult Create()
        {
            ViewBag.AccountID = new SelectList(db.Accounts, "ID", "Name");
            return View();
        } 

        //
        // POST: /Summary/Create

        [HttpPost]
        public ActionResult Create(PaymentJournalEntry paymentjournalentry)
        {
            if (ModelState.IsValid)
            {
                db.PaymentJournalEntries.Add(paymentjournalentry);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.AccountID = new SelectList(db.Accounts, "ID", "Name", paymentjournalentry.AccountID);
            return View(paymentjournalentry);
        }
        
        //
        // GET: /Summary/Edit/5
 
        public ActionResult Edit(int id)
        {
            PaymentJournalEntry paymentjournalentry = db.PaymentJournalEntries.Find(id);
            ViewBag.AccountID = new SelectList(db.Accounts, "ID", "Name", paymentjournalentry.AccountID);
            return View(paymentjournalentry);
        }

        //
        // POST: /Summary/Edit/5

        [HttpPost]
        public ActionResult Edit(PaymentJournalEntry paymentjournalentry)
        {
            if (ModelState.IsValid)
            {
                db.Entry(paymentjournalentry).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.AccountID = new SelectList(db.Accounts, "ID", "Name", paymentjournalentry.AccountID);
            return View(paymentjournalentry);
        }

        //
        // GET: /Summary/Delete/5
 
        public ActionResult Delete(int id)
        {
            PaymentJournalEntry paymentjournalentry = db.PaymentJournalEntries.Find(id);
            return View(paymentjournalentry);
        }

        //
        // POST: /Summary/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            PaymentJournalEntry paymentjournalentry = db.PaymentJournalEntries.Find(id);
            db.PaymentJournalEntries.Remove(paymentjournalentry);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}